// index.js
Page({
    data: {
        username:'',
        login:{
            name:'',
            password:''
        },
        radio_checked:'false'
    },
    loginForm:function(data) {
        var username = data.detail.value.userName;
        var password = data.detail.value.password;
        var that = this;
        if(that.data.radio_checked == 'true') {
            wx.request({
                url: 'http://localhost:8080/user/login?name='+username+'&password='+password,
                method:'GET',
                header:{
                    'content-type':'application/json'
                },
                success:function(res){
                    console.log(res.data);
                    if(res.data.msg == "密码错误"){
                        wx.showModal({
                            title: '提示',
                            content: '密码错误！',
                          })
                    }else{
                        if(res.data.msg == "用户不存在"){
                            wx.showModal({
                                title: '提示',
                                content: '用户不存在！',
                            })
                        }else{
                            console.log("success");
                            var app = getApp();
                            app.data.useId = res.data.data.useId;
                            wx.reLaunch({
                                url: '/pages/index/index',  
                            })
                        }
                    } 
                    
                    
                }
            })
        }else{
            wx.showModal({
              title: '提示',
              content: '请阅读《用户协议》《隐私协议》！',
            })
        }
    },
    radioChange:function(e) {
        this.data.radio_checked = e.detail.value;
        console.log(this.data.radio_checked);
    },
    register() {
        wx.navigateTo({
          url: '/pages/register/register',
        })
    },
    onLoad:function(option) {
        this.username = option.username;
        var name = option.username;
        this.setData({
            username:name
        }), 
        console.log(this.username);
    }
})